﻿namespace PublicModels.APIObjs;

public class Weather:APIObjBase
{
    public string? returnCode { get; set; }

    public override int status 
    {
        get
        {
            if (int.TryParse(returnCode, out int result))
                return result;
            return -1;
        }
    }

    public List<WeatherItem>? list { get; set; }

    public bool Sunny => GetValue("PRE_6H") is "0.0";

    public string Temperature => GetValue("TEM");

    public string Wind => GetValue("WINS");

    public string RHU => GetValue("RHU");

    public string RainIn3h => GetValue("PRE_3H");

    public string RainIn6h => GetValue("PRE_6H");

    public string RainIn12h => GetValue("PRE_12H");

    private string GetValue(string valueName)
    {
        var temp = list?.Where(item => item.fastEle == valueName);
        if (temp is null || temp.Count() is 0)
            return string.Empty;
        var r = temp.ToArray()[0].value;
        return r is null ? string.Empty : r;
    }
}

public class WeatherItem
{
    public string? unit { get; set; }

    public string? validTime { get; set; }

    public string? value { get; set; }

    public string? fastEle { get; set; }

}
